package name.huzhenbo.java.algorithm.talent;

class PowerSet {
    private int[] set;

    public PowerSet(int[] set) {
        this.set = set;
    }

    public void go() {
        _go(0, set);
    }

    private void _go(int i, int[] current) {
        if (i == set.length) {
            print(current);
        } else {
            _go(i + 1, current);
            _go(i + 1, delete(current, i));
        }
    }

    private void print(int[] current) {
        for(int i = 0; i < current.length; i++){
            System.out.print(current[i]);
            if(i + 1 != current.length) System.out.print(", ");
        }
        System.out.print("\n"); 
    }

    private int[] delete(int[] current, int i) {
        int[] copyOfCurrent = new int[current.length - 1];
        for(int j = 0; j < copyOfCurrent.length; j++){
            copyOfCurrent[j] = j < i ? current[j] : current[j + 1];
        }
        return copyOfCurrent;
    }
}
